from app.crud.auth_crud import AuthCRUD
from app.schemas.result_schema import ResultModel, ResultFormat
from app.schemas.user_schema import UserLogin, UserLoginOut


class AuthController:
    def __init__(self, crud: AuthCRUD):
        self.crud = crud

    async def login(self, login_in: UserLogin)-> ResultModel[UserLoginOut]:
        result = await self.crud.login_by_account(login_in=login_in)
        return ResultFormat.result_model(data=result)

    async def login_by_wechat(self,state=None)-> str:
        return await self.crud.login_by_wechat(state=state)

    async def refresh_token(self,token:str,refresh_token: str) -> ResultModel[UserLoginOut]:
        result = await self.crud.refresh_token(token=token, refresh_token=refresh_token)
        return ResultFormat.result_model(data=result)